NS_PER_TICK must be a s64 quantity. It is compared with
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 13 Oct 2005 07:38:49 +0000 (08:38 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 13 Oct 2005 07:38:49 +0000 (08:38 +0100)
possibly -ve values which we do not want to 'promote' to
big +ve values.

Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c

index ea09ebbb952f0179a3f8264949c1534555c803c0..11572709559284187cf3d3a2a7cee3a9ec558fc3 100644 (file)
@@ -122,7 +122,8 @@ static u32 shadow_tv_version;
 static u64 processed_system_time;   /* System time (ns) at last processing. */
 static DEFINE_PER_CPU(u64, processed_system_time);
 
-#define NS_PER_TICK (1000000000ULL/HZ)
+/* Must be signed, as it's compared with s64 quantities which can be -ve. */
+#define NS_PER_TICK (1000000000LL/HZ)
 
 static inline void __normalize_time(time_t *sec, s64 *nsec)
 {
@@ -235,9 +236,9 @@ static void __update_wallclock(time_t sec, long nsec)
 
        /* Adjust wall-clock time base based on wall_jiffies ticks. */
        wc_nsec = processed_system_time;
-       wc_nsec += (u64)sec * 1000000000ULL;
-       wc_nsec += (u64)nsec;
-       wc_nsec -= (jiffies - wall_jiffies) * (u64)(NSEC_PER_SEC / HZ);
+       wc_nsec += sec * (u64)NSEC_PER_SEC;
+       wc_nsec += nsec;
+       wc_nsec -= (jiffies - wall_jiffies) * (u64)NS_PER_TICK;
 
        /* Split wallclock base into seconds and nanoseconds. */
        tmp = wc_nsec;
@@ -437,7 +438,7 @@ int do_settimeofday(struct timespec *tv)
         * be stale, so we can retry with fresh ones.
         */
        for ( ; ; ) {
-               nsec = (s64)tv->tv_nsec - (s64)get_nsec_offset(shadow);
+               nsec = tv->tv_nsec - get_nsec_offset(shadow);
                if (time_values_up_to_date(cpu))
                        break;
                get_time_values_from_xen();
@@ -558,7 +559,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        }
        while (!time_values_up_to_date(cpu));
 
-       if (unlikely(delta < (s64)-1000000) || unlikely(delta_cpu < 0)) {
+       if (unlikely(delta < -1000000LL) || unlikely(delta_cpu < 0)) {
                printk("Timer ISR/%d: Time went backwards: "
                       "delta=%lld cpu_delta=%lld shadow=%lld "
                       "off=%lld processed=%lld cpu_processed=%lld\n",
@@ -802,7 +803,7 @@ static inline u64 jiffies_to_st(unsigned long j)
                 * but that's ok: we'll just end up with a shorter timeout. */
                if (delta < 1) 
                        delta = 1;
-               st = processed_system_time + ((u64)delta * NS_PER_TICK);
+               st = processed_system_time + (delta * (u64)NS_PER_TICK);
        } while (read_seqretry(&xtime_lock, seq));
 
        return st;